package com.jade.editor.domain.parts;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class SettingsDomain extends Dialog {

	public int _x = 0;
	public int _y = 0;
	
	/**
	 * Create the dialog.
	 * @param parentShell
	 */
	public SettingsDomain(Shell parentShell, Point size) {
		super(parentShell);
		_x = size.x;
		_y = size.y;
	}

	public Point getSize(){
		return new Point(_x, _y);
	}
	/**
	 * Create contents of the dialog.
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		container.setLayout(null);
		
		final Spinner xSpinner = new Spinner(container, SWT.BORDER);
		xSpinner.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				_x = xSpinner.getSelection();
			}
		});
		xSpinner.setBounds(27, 10, 70, 22);
		xSpinner.setMinimum(50);
		xSpinner.setMaximum(2048);
		xSpinner.setSelection(_x);
		
		final Spinner ySpinner = new Spinner(container, SWT.BORDER);
		ySpinner.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				_y = ySpinner.getSelection();
			}
		});
		ySpinner.setBounds(137, 10, 70, 22);
		ySpinner.setMinimum(50);
		ySpinner.setMaximum(2048);
		ySpinner.setSelection(_y);
		
		Label lblX = new Label(container, SWT.NONE);
		lblX.setBounds(10, 17, 55, 15);
		lblX.setText("X:");
		
		Label lblY = new Label(container, SWT.NONE);
		lblY.setBounds(119, 17, 55, 15);
		lblY.setText("Y:");

		return container;
	}

	/**
	 * Create contents of the button bar.
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
				true);
		createButton(parent, IDialogConstants.CANCEL_ID,
				IDialogConstants.CANCEL_LABEL, false);
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(240, 125);
	}
}
